import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'positionThroughQueryNewM',
  state: {},
  effects: {
    //查询持仓穿透列表
    *queryTableList({ payload, callback }, { call, put }) {
      const res = yield call(api.positionThroughQueryNew.queryTableList, payload);
      if (res && res.code == 0) {
        let temp = res.data || {};
        callback(temp);
      } else {
        callback();
        message.error(res ? res.msg || '查询持仓穿透列表失败！' : '查询持仓穿透列表失败！');
      }
    },
    //查询最近一次交易日
    *queryTradeDate({ payload, callback }, { call, put }) {
      const res = yield call(api.positionThroughQueryNew.queryTradeDate, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res ? res.msg || '查询最近一次交易日失败' : '查询最近一次交易日失败');
      }
    },
    //模糊查询证券代码下拉列表
    *queryTradingCodeList({ payload, callback }, { call, put }) {
      let fetchId = payload.fetchId;
      delete payload.fetchId;
      const res = yield call(api.positionThroughQueryNew.queryTradingCodeList, payload);
      if (res && res.code == 0) {
        console.log(fetchId);
        res.data?.map((item) => {
          item.value = item.id;
          item.title = item.tradingCode + '-' + item.name;
        });
        callback(res.data, fetchId);
      } else {
        callback();
        message.error(res ? res.msg || '模糊查询证券代码下拉列表失败' : '模糊查询证券代码下拉列表失败');
      }
    },

    reducers: {
      save(state, { payload }) {
        return {
          ...state,
          ...payload,
        };
      },
    },
  },
};
